package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.annotation.RequiresPermissionsDesc;
import com.cskaoyan.market.db.domain.MarketAd;
import com.cskaoyan.market.service.AdminAdService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("admin/ad")
public class AdminAdController{

    @Autowired
    AdminAdService adminAdService;


    @GetMapping("list")
    @RequiresPermissions("admin:ad:list")
    @RequiresPermissionsDesc(menu = {"商场管理", "广告管理"},button = "查询")
    public Object list(Integer page, Integer limit, String sort, String order, String name, String content) {

        List<MarketAd> adList = adminAdService.list(page, limit, sort, order,name, content);
        //对于分页查询的这些接口，那么我们需要调用oKlIST方法
        Object o = ResponseUtil.okList(adList);
        return o;
    }

    @PostMapping("update")
    @RequiresPermissions("admin:ad:delete")
    @RequiresPermissionsDesc(menu = {"推广管理", "广告管理"},button = "编辑")
    public Object update(@RequestBody MarketAd marketAd){
        adminAdService.update(marketAd);
        return ResponseUtil.ok(marketAd);
    }

    @PostMapping("delete")
    @RequiresPermissions("admin:ad:delete")
    @RequiresPermissionsDesc(menu = {"推广管理", "广告管理"},button = "删除")
    public Object delete(@RequestBody MarketAd marketAd){
        Integer id= marketAd.getId();
        int i=adminAdService.delete(id);
        return ResponseUtil.ok(i);
    }

    @PostMapping("create")
    @RequiresPermissions("admin:ad:delete")
    @RequiresPermissionsDesc(menu = {"推广管理", "广告管理"},button = "添加")
    public Object create(@RequestBody MarketAd marketAd) {
        int i=adminAdService.create(marketAd);
        return ResponseUtil.ok(i);
    }
}
